﻿using FunctionalCLR.Shell;
using FunctionalCLR.Core;
using Zove.Runtime.FunctionalCLR;
using Zove.Runtime;

namespace Zove.Numerics {
    class ZoveNumericsParser : ContextParser {

        public ZoveNumericsParser(string expr, IContext context)
            : base(expr, context) {
        }

        public override IdentifierNode GetIdenitiferNode(string value) {
            if (value.ToLower().Equals("true")
                || value.ToLower().Equals("false")) {
                IdentifierNode node = new IdentifierNode();
                node.Value = value;

                return node;
            }

            FactorNode fn = new FactorNode();
            fn.Factor = (RuntimeFactor)base.context.GetVariableByName(value);
            if (fn.Factor == null) {
                fn.Factor = (RuntimeFactor)context.AddVariable(value);
            }

            return fn;
        }
    }
}
